import java.util.ArrayList;
//
//  @ Project : Project1
//  @ File Name : Creature.java
//  @ Date : 1/21/2013
//  @ Author : Graham Tapscott
//
//




public class Creature implements IMobile, Comparable<Creature> {
	
	// Instance variables
	protected ArrayList<Treasure> treasureList;
	protected ArrayList<Artifact> artifactsList;
	protected Integer empathy = 0;
	protected Integer fear = 0;
	protected Integer partyIndex = 0;
	protected String name = "";
	protected Integer index;
	protected Integer mana = 0;
	protected Integer health = 0;
	protected String type = "";
	protected Double carryCapacity = 0.0;
	
	/**
	 * Creature - no-arg constructor
	 */
	public Creature() {
		treasureList = new ArrayList<Treasure>();
		artifactsList = new ArrayList<Artifact>();
	}

	/**
	 * Creature - argumented constructor, this can be used to instantiate a new object from a 
	 * string representation of the object
	 * @param input a string representation of the object
	 */
	public Creature(String[] input) {
		this();		
		this.deSerialize(input);
	}
	
	/**
	 * Creature - argumented constructor, this is to be used only as a comparison functions
	 * @param idx
	 */
	public Creature(Integer idx) {
		this();
		index = idx;
	}

	/**
	 * getMana - mana variable getter
	 * @return the mana variable
	 */
	public Integer getMana() {
		return mana;
	}
	
	/**
	 * addItem - adds an item to the item list
	 * @param i an item to add to the item list
	 */
	public void addItem(Item i) {
		if(i.getClass()==Treasure.class)
			treasureList.add((Treasure)i);
		else
			if(i.getClass()==Artifact.class)
				artifactsList.add((Artifact)i);
	}
	
	/**
	 * getHealth - health variable getter
	 * @return the health variable
	 */
	public Integer getHealth() {
		return health;
	
	}
	
	/**
	 * getFear - fear variable getter
	 * @return the fear variable
	 */
	public Integer getFear() {
		return fear;
	
	}
	
	/**
	 * getEmpathy - empathy variable getter
	 * @return the empathy variable
	 */
	public Integer getEmpathy() {
		return empathy;
	
	}
	
	/***
	 * getArtifacts - artifacts list getter
	 * @return a list of artifacts
	 */
	public ArrayList<Artifact> getArtifacts() {
		return artifactsList;
	}
	
	public String getName() {
		return name;
	}
	
	public Integer getIndex() {
		return index;
	}
	
	public Integer getPartyIndex() {
		return partyIndex;
	}
	
	public String getType() {
		return type;
	}
	
	/**
	 * dumpObject - dumps the object and recursively dumps all objects in the instance lists for 
	 * treasureList and artifactsList
	 * @return a string representing this and all sub-objects
	 */
	public String dumpObject(){
		String result = this.serialize() + Utils.newLine;
		for(int i=0;i<treasureList.size();i++){
			result += Utils.tabChar + Utils.tabChar + treasureList.get(i).toString() + Utils.newLine;
		}
		for(int i=0;i<artifactsList.size();i++){
			result += Utils.tabChar + Utils.tabChar+ artifactsList.get(i).toString() + Utils.newLine;
		}
		return result;
	}
	
	public String toString() {
		return serialize();
	}
	
	public void deSerialize(String[] mobile) {
		this.index = Integer.parseInt(mobile[1].trim());
		this.type = mobile[2].trim();
		this.name = mobile[3].trim();
		this.partyIndex = Integer.parseInt(mobile[4].trim());
		this.empathy = Integer.parseInt(mobile[5].trim());
		this.fear = Integer.parseInt(mobile[6].trim());
		this.carryCapacity = Double.parseDouble(mobile[7].trim());		
	}
	
	public String serialize() {
		String mobile = "c:" + this.index + ":" + this.type + ":" + this.name + ":"
				+ this.partyIndex + ":" + this.empathy + ":" + this.fear + ":"
				+ this.carryCapacity;
		
		return mobile;
	}
	
	public int compareTo(Creature otherCreature) {
		if(this.index > otherCreature.getIndex())
			return 1;
		else
			if(this.index < otherCreature.getIndex())
				return -1;
				else
					return 0;					
	}	
}

